package com.bysj.agent.service.impl;

import bean.ChatMessage;
import com.bysj.agent.feign.UserFeignService;
import com.bysj.agent.service.MessageService;
import com.bysj.agent.service.UserService;
import com.bysj.agent.utils.R;
import entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserFeignService userFeignService;
    //收藏商品


    /**
     * 获取商品详细信息
     * @return
     */
    @Override
    public R<AiProductInfoDetailVo> getProductInfo()  {
        ChatMessage chatMessage = MessageService.getMessage();
        String productId = chatMessage.getProductId();
        R<ProductInfoDetailVo> res= userFeignService._getProductInfo(productId);
        ProductInfoDetailVo productInfoDetailVo = res.getResult();
        AiProductInfoDetailVo aiProductInfoDetailVo = new AiProductInfoDetailVo();
        aiProductInfoDetailVo.copy(productInfoDetailVo);
        return R.ok(aiProductInfoDetailVo);
//        return userFeignService._getProductInfo(productId);
    }

    /**
     * 创建收藏
     * @return
     */
    @Override
    public R createCollect() {
        ChatMessage chatMessage = MessageService.getMessage();
        ProductCollect productCollect = new ProductCollect();
        productCollect.setProductId(chatMessage.getProductId());
        productCollect.setUserId(chatMessage.getUserId());
        return userFeignService._create(productCollect);
    }

    /**
     * 删除收藏
     * @return
     */
    @Override
    public R deleteCollect() {
        String userId = new String();
        ChatMessage chatMessage = MessageService.getMessage();
        String productId = chatMessage.getProductId();
        userId = chatMessage.getUserId();
        ProductCollect productCollect = new ProductCollect();
        productCollect.setProductId(productId);
        productCollect.setUserId(userId);
        return userFeignService._delete(productCollect);
    }

    /**
     * 创建订单
     * @param address
     * @param idname
     * @param phone
     * @return
     */
    @Override
    public R<String> createOrder(String address, String idname, String phone) {
        //创建订单
        ChatMessage chatMessage = MessageService.getMessage();
        AiProductOrderDto aiProductOrderDto = new AiProductOrderDto();
        aiProductOrderDto.setAddress(address);
        aiProductOrderDto.setIdname(idname);
        aiProductOrderDto.setPhone(phone);
        aiProductOrderDto.setProductId(chatMessage.getProductId());
        aiProductOrderDto.setUserId(chatMessage.getUserId());
        R<String> orderId = userFeignService.aiCreateOrder(aiProductOrderDto);
        //创建支付订单
        AiPaymentOrderDto aiPaymentOrderDto = new AiPaymentOrderDto();
        aiPaymentOrderDto.setOrderId(orderId.getResult());
        aiPaymentOrderDto.setUserId(chatMessage.getUserId());

        return userFeignService.aiCreatePaymentOrder(aiPaymentOrderDto);
    }

}
